#pragma once
#include <deque>
#include <vector>

#include "Object.h"

using namespace std;

#define LIMIT_W_H 10

class QuadNode
{
public:
	vector<Object*> ListObj;
	 
	RECT* m_Rect;

	QuadNode *LT, *RT, *LB, *RB;
	//constructor
	QuadNode()
	{
		m_Rect = NULL;
		LT = RT = LB = RB = NULL;
	}

	QuadNode( int left, int top, int width, int height)
	{
		m_Rect				= new RECT();
		m_Rect->left		= left;
		m_Rect->top			= top;
		m_Rect->right		= m_Rect->left + width;
		m_Rect->bottom		= m_Rect->top + height;
		LT = RT = LB = RB = NULL;
	}
};
class CQuadTree
{
public:
	//root
	QuadNode *m_qRoot;
	int m_nMapWidth;
	int m_nMapHeight;
	int m_nCount;
	//constructor
	CQuadTree(int w, int h);
	~CQuadTree();
	//function
	void AddObj(QuadNode* _root, Object* _reb);
	void getObjInRect( QuadNode* root, RECT Screen, vector<Object*>& result);
	void getAllObj(QuadNode* root, vector<Object*> &result);
	QuadNode* getTreeRoot(){return m_qRoot;}
	//RECT* getRect( QuadNode* root, RECT r);
	Object* CheckCollision( QuadNode* root, RECT r, int seq);
	void CheckCollision(QuadNode* root, RECT r, int seq, vector<Object*>& result);
	void UpdatePosition(QuadNode* root);
	void updateDraw(RECT _Screen, int DeltaTime, int moveCame);
	void DrawObj(RECT _Screen);
	void RemoveAll(QuadNode *root);
};